Ext.define('CompanyInfo', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "ChineseFullName"   //企业中文名称
		, "ChineseShortName"   //企业中文简称
		, "EnglishFullName"   //企业英文全称
		, "EnglishShortName"   //企业英文简称
		, "BankNumber"   //工商注册号
		, "RegisterRoom"   //注册地
		, "Remark"   //备注
		, "Property"   //性质
		, { name: "Scope", type: "int"}   //规模
		, "HomePage"   //主页
		, "HigherUnit"   //上级单位
		, "UnderGroup"   //所属集团
		, "WorkPlace"   //办公所在地
		, "CompanyPlace"   //公司所在地
		, "Other"   //其他业务信息
        , 'UserID'//服务人员ID
        , 'UserName'//服务人员名称
        , "SuperiorID"//父ID
	],
    idProperty: "Id"
});

Ext.define('SHApp.CompanyManage.CompanyInfo.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.companymanag.grid',
    requires: ['SHApp.CompanyManage.CompanyInfo.Form','SHApp.EmployeeInfo.BasicInfo.CompanyComboBox'],
    txtChineseFullNameID: 'txtChineseFullName',
    dataModel: "CompanyInfo",
    dataUrl: "api/companyinfo?format=json",
    parentID: null,
    parentName: "",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtChineseFullNameID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
        
    },
    loadByParentID: function (id, name) {
        var me = this;
        me.parentID = id;
        me.parentName = name;
        me.clearFilters();
        me.addFilter("SuperiorID", id);
        me.loadByFilter();
    },
    creatColumns: function () {
        var me = this;
        me.columns = [{
            text: "Id",
            flex: 1,
            dataIndex: 'Id',
            sortable: false,
            hidden: true
        }, {
            text: "SuperiorID",
            flex: 1,
            dataIndex: 'SuperiorID',
            sortable: false,
            hidden: true
        }, {
            text: "UserID",
            flex: 1,
            dataIndex: 'UserID',
            sortable: false,
            hidden: true
        }, {
            text: "企业中文名称",
            width: 200,
            dataIndex: 'ChineseFullName',
            sortable: true
        }, {
            text: "企业英文全称",
            width: 100,
            dataIndex: 'EnglishFullName',
            sortable: true
        }, {
            text: "办公所在地",
            width: 100,
            dataIndex: 'WorkPlace',
            sortable: true
        }, {
            text: "公司所在地",
            width: 100,
            dataIndex: 'CompanyPlace',
            sortable: true
        }, {
            text: "注册地",
            width: 100,
            dataIndex: 'RegisterRoom',
            sortable: true
        }, {
            text: "工商注册号",
            width: 100,
            dataIndex: 'BankNumber',
            sortable: true
        }, {
            text: "客户负责人",
            width: 100,
            dataIndex: 'UserName',
            sortable: true
        }, {
            text: "企业性质",
            width: 100,
            dataIndex: 'Property',
            sortable: true
        }, {
            text: "规模",
            width: 100,
            dataIndex: 'Scope',
            sortable: true
        }, {
            text: "所属集团",
            width: 100,
            dataIndex: 'UnderGroup',
            sortable: true
        }, {
            text: "上级单位",
            width: 100,
            dataIndex: 'HigherUnit',
            sortable: true
        }, {
            text: "企业中文简称",
            width: 100,
            dataIndex: 'ChineseShortName',
            sortable: true
        }, {
            text: "企业英文缩写",
            width: 100,
            dataIndex: 'EnglishShortName',
            sortable: true
        }, {
            text: "主页",
            width: 100,
            dataIndex: 'HomePage',
            sortable: true
        }, {
            text: "其他业务信息",
            width: 100,
            dataIndex: 'Other',
            sortable: true
        }, {
            text: "备注",
            width: 100,
            dataIndex: 'Remark',
            sortable: true
        }]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
		    {
		        xtype: "textfield",
		        fieldLabel: '企业中文名称:',
		        labelWidth: 80,
		        name: 'ChineseFullName',
		        id: me.txtChineseFullNameID,
		        width: 280
		    }, {
		        xtype: 'button',
		        text: '查询',
		        iconCls: 'icon-btn-search',
		        handler: function () {
		            me.clearFilters();
		            var vChineseFullName = me.down("#" + me.txtChineseFullNameID).getValue();
		            if (vChineseFullName && vChineseFullName.length > 0) {
		                me.addFilter("ChineseFullName", vChineseFullName);
		            }
		            if (me.parentID != null) {
		                me.addFilter("SuperiorID", me.parentID);
		            }
		            me.loadByFilter();
		        }
		    }, '->', {
		        xtype: 'button',
		        text: '添加',
		        id: me.btnAddID,
		        iconCls: 'icon-btn-add',
		        handler: function () {
		            var win = me.getForm('SHApp.CompanyManage.CompanyInfo.Form');
		            var HigherUnit = "";
		            if (me.parentID == '00000000-0000-0000-0000-000000000000') {
		                HigherUnit = "";
		            } else {
		                HigherUnit = me.parentName;
		            }
		            win.loadRecord(new CompanyInfo({ Id: null, SuperiorID: me.parentID, HigherUnit: HigherUnit }));
		            win.Show("添加");
		        }
		    }, {
		        xtype: 'button',
		        disabled: true,
		        id: me.btnEditID,
		        text: '修改',
		        iconCls: 'icon-btn-edit',
		        handler: function () {
		            var rs = me.getSelectionModel().getSelection();
		            if (rs) {
		                if (rs.length > 0) {
		                    // rs[0].data.StartDate = formatDate(rs[0].data.StartDate);                           
		                    me.EditData(me.getForm('SHApp.CompanyManage.CompanyInfo.Form'));
		                }
		            }
		        }
		    }, ' ', {
		        xtype: 'button',
		        disabled: true,
		        id: me.btnDeleteID,
		        text: '删除',
		        iconCls: 'icon-btn-delete',
		        handler: function () {
		            me.DeleteData();
		        }
		    }
        ]
    }
})

